import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// 0.模块化编程
Vue.use(VueRouter)

// 1. 路由组件
// 路由懒加载
import ErrorRoutes from '@/views/errorpages/route'
import LoginRoutes from '@/views/logins/route'
import MainRoutes from '@/views/main/route'
import SearchRuotes from '@/views/search/route'
import DetailsRoutes from '@/views/details/route'
import AddessRoutes from '@/views/address/route'
import CollectRotes from '@/views/collect/route'
import PraiseRotes from '@/views/praise/route'

// 2. 定义路由配置选项
const routes = [
    {
        path: '/',
        redirect: {
        name: 'guide'
        }
    },
    {
        path: '/guide',
        name: 'guide',
        component: () => import('@/views/guide/guide.vue')
    },
    ...ErrorRoutes,
    ...MainRoutes,
    ...LoginRoutes,
    ...SearchRuotes,
    ...DetailsRoutes,
    ...AddessRoutes,
    ...CollectRotes,
    ...PraiseRotes,
    {
        path: '*',
        redirect: {
        name: '404'
        }
    },
]

// 3. 创建路由对象
const router = new VueRouter({
    routes,
    mode: 'hash'
})

// 4. 暴露挂载到根实例
export default router